package hqyj.example.itemservice.controller;

import hqyj.example.itemservice.domain.Goods;
import hqyj.example.itemservice.service.GoodsService;
import hqyj.example.itemservice.view.Catalog;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("goods")
public class GoodsController {

    @Resource
    private GoodsService goodsService;


    @GetMapping("all")
    public Map<String,Object> queryAllGoodsList(){
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<Goods> goodsList = goodsService.queryAllGoodsList();
            result.put("code", 200);
            result.put("msg", "查询所有商品列表成功！");
            result.put("data", goodsList);
            return result;
        } catch (Exception ex) {
            ex.printStackTrace();
            result.put("code", 400);
            result.put("msg", "程序出现错误！");
            return result;
        }
    }


    @GetMapping("query/{catalog}")
    public Map<String,Object> queryAllGoodsListByCatalogName(@PathVariable("catalog")  String catalogName){
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<Goods> goodsList = goodsService.queryAllGoodsListByCatalog(catalogName);
            result.put("code", 200);
            result.put("msg", "查询所有商品列表成功！");
            result.put("data", goodsList);
            return result;
        } catch (Exception ex) {
            ex.printStackTrace();
            result.put("code", 400);
            result.put("msg", "程序出现错误！");
            return result;
        }
    }

}
